package com.wk.paradise.redis.utils;

import com.wk.paradise.redis.config.redisConfig.RedisPool;
import java.util.List;
import redis.clients.jedis.Jedis;

/**
 * @Classname RedisListUtil
 * @Description TODO
 * @Date 2019/12/30 13:57
 * @Author by weikai
 */
public final class RedisListUtil {

  private RedisListUtil() {
  }

  /**
   * 获取范围list数据
   * @param redisPool
   * @param key
   * @param start
   * @param end
   * @return
   */
  public static List<String> rList(RedisPool redisPool, final String key, final int start,
      final int end) {

    Jedis jedis = redisPool.getResource();
    try {
      return jedis.lrange(key, start, end);
    } finally {
      jedis.close();
    }
  }

  /**
   * 获取对应key的长度
   * @param redisPool
   * @param key
   * @return
   */
  public static Long llen(RedisPool redisPool,final String key){
    Jedis jedis = redisPool.getResource();
    try {
      return jedis.llen(key);
    }finally {
      jedis.close();
    }
  }

  /**
   * 在redis中添加list数据类型的值
   * @param redisPool
   * @param key
   * @param strings
   */
  public static void rpush(RedisPool redisPool,final String key,String... strings){
    Jedis jedis = redisPool.getResource();
    try {
      jedis.rpush(key,strings);
    }finally {
      jedis.close();
    }
  }
}
